package tjs.study.notes.dotest.redis;

import org.redisson.Redisson;
import org.redisson.RedissonLock;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

import java.util.concurrent.TimeUnit;

/**
 * Created by Nicky.Tang on 2021/11/11 12:36 下午
 *
 * @since 02.12.10
 */
public class DoTestOfRedissionAPI {
    /**
     * // 加锁
     * {@link RedissonLock#tryLockInnerAsync(long, long, java.util.concurrent.TimeUnit, long, org.redisson.client.protocol.RedisStrictCommand)}
     */
    public static void main(String[] args) throws Exception {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://127.0.0.1:6379");
        RedissonClient client = Redisson.create(config);
        RLock rLock = client.getLock("/a/b/1");
        try {
            if(rLock.tryLock(10,/*10,*/ TimeUnit.SECONDS)){
                Thread.currentThread().sleep(8000);
            }
        }finally {
            rLock.unlock();
        }
    }
}
